package com.qdlc.p2p.dal.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.dal.common.dao.jpa.BaseDaoImpl;
import com.qdlc.p2p.dal.common.model.jpa.OrderFilter.OrderType;
import com.qdlc.p2p.dal.common.model.jpa.QueryParam;
import com.qdlc.p2p.dal.dao.SiteDao;
import com.qdlc.p2p.dal.dto.Site;
import com.qdlc.p2p.dal.model.SiteModel;

@Repository("siteDao")
public class SiteDaoImpl extends BaseDaoImpl<Site> implements SiteDao {
	
	@Override
	public List<Site> list() {
		QueryParam param = QueryParam.getInstance();
		param.addParam("pid", 0);
		param.addOrder(OrderType.ASC, "sort");
		return findByCriteria(param);
	}

	@Override
	public List<Site> list(long pid, int status) {
		QueryParam param = QueryParam.getInstance();
		param.addParam("pid", pid).addParam("status", status);
		return findByCriteria(param);
	}

	@Override
	public List<Site> siteList(SiteModel model) {
		StringBuffer sql = new StringBuffer();
        sql.append("select * from ");
        sql.append(Global.DB_PREFIX).append("site ");
        sql.append("order by id desc ");
		Query query = em.createNativeQuery(sql.toString(), Site.class);
		List<Site> list = query.getResultList();
		return list;
	}
}